--[[
	与后台Web通信接口

--]]

local httpc = require("http.httpc")
local cjson = require("cjson")

local M = class("WebProxy")

function M:ctor()
    self.web_host = g.server_config.web.gm
    self:register()
end

--热更会自动调用
function M:register()

end

function M:checkToken(data)
    return g.message:httpPost("gm", "/sevenflower/api/v1/check/checkToken", data)
end

----是否报名了比赛
--function M:matchSign(mid, rid)
--    local url = "/sevenflower/api/v1/match/getSigupRoom?"
--    url = string.format(url.."mid=%s", mid, rid)
--    httpc.timeout = 800
--    local ok, code, body = pcall(httpc.get, self.web_host, url)
--    if not ok or not code or not body then
--        g.log:err("matchSign web_host:%s, url:%s", self.web_hos, url)
--        return
--    end
--    local ok, res = xpcall(cjson.decode, debug.traceback, body)
--    if not ok or not res.code or res.code ~= 0 then
--        g.log:err("matchSign", body)
--        return {code = res.code, msg = res.msg}
--    end
--end

--开始比赛
function M:matchStart(rid)
    return g.message:httpPost("gm", "/sevenflower/api/v1/match/callMatch", {roomid=rid, sign_type=1})
end

--取消比赛
function M:matchCancel(rid)
    return g.message:httpPost("gm", "/sevenflower/api/v1/match/cancelMatch", {roomid=rid, sigup_type=3})
end

--比赛输了
function M:matchLost(rid, uid)
    return g.message:httpPost("gm", "/sevenflower/api/v1/match/lostmatch", {roomid=rid, mid=uid, sigup_type=4})
end

--比赛结束
function M:matchEnd()
    return g.message:httpPost("gm", "/sevenflower/api/v1/sendMsgWx", {})
end

--报名
function M:matchSign(rid, mid, sigup_type)
    sigup_type = sigup_type or 1
    return g.message:httpPost("gm", "/sevenflower/api/v1/match/mttSignup", {roomid=rid, mid=mid, sigup_type=sigup_type})
end


return M